package com.lwp.test.aoptest.config;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Component
@Aspect
//@Order(2)
public class AopConfig2 {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

//    @Pointcut("execution(* com.lwp.test.aoptest.service.*..*.*(..))")
    @Pointcut("execution(* com.lwp.test.aoptest.service..*.*(..))")
    public void servicePointcut() {
        // 切入点1
    }

    @Around("servicePointcut()")
    public Object serviceAround(ProceedingJoinPoint pjp) throws Throwable {
        // 获取参数
        Object[] args = pjp.getArgs();
        MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
        long start = System.currentTimeMillis();
        logger.info("AopConfig2 请求参数： {}", args);
        Object proceed = pjp.proceed(args);
        logger.info("AopConfig2 响应： {}", proceed);
        logger.info("AopConfig2 方法 {} 耗时： {}ms", methodSignature.getName(), System.currentTimeMillis() - start);
        return proceed;
    }
}
